package io.renren.modules.cw.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.cw.entity.CwBedEntity;
import io.renren.modules.cw.service.CwBedService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author wangshijun
 * @email 3088916141@qq.com
 * @date 2021-05-06 13:40:14
 */
@RestController
@RequestMapping("cw/cwbed")
public class CwBedController {
    @Autowired
    private CwBedService cwBedService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("cw:cwbed:list")
    public R list(@RequestParam Map<String, Object> params){
        //ageUtils page = cwBedService.queryPage(params);
        PageUtils page = cwBedService.selectPageVo(params);

        return R.ok().put("page", page);
    }

    /**
     * 获取床位列表：
     *  flag ：true表示已住，false/null表示未住
     * @return
     */
    @RequestMapping("/getBedList")
    public R getBedList(@RequestParam Map<String,Object> params){
        QueryWrapper<CwBedEntity> wrapper = new QueryWrapper<>();
        Object flag = params.get("flag");
        if(flag!=null&&"true".equals(flag)){
            wrapper.isNotNull("customer_id");
        }else {
            wrapper.isNull("customer_id");
        }
        List<CwBedEntity> list = cwBedService.getBaseMapper().selectList(wrapper);
        return R.ok().put("data", list);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{bedId}")
    @RequiresPermissions("cw:cwbed:info")
    public R info(@PathVariable("bedId") Integer bedId){
		CwBedEntity cwBed = cwBedService.getById(bedId);

        return R.ok().put("cwBed", cwBed);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("cw:cwbed:save")
    public R save(@RequestBody CwBedEntity cwBed){
		cwBedService.save(cwBed);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("cw:cwbed:update")
    public R update(@RequestBody CwBedEntity cwBed){
		cwBedService.updateById(cwBed);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("cw:cwbed:delete")
    public R delete(@RequestBody Integer[] bedIds){
		cwBedService.removeByIds(Arrays.asList(bedIds));

        return R.ok();
    }

}
